package com.hzjy.api.service.impl;

import com.hzjy.api.mapper.ApiDictDataMapper;
import com.hzjy.common.core.domain.entity.SysDictData;
import com.hzjy.common.utils.DictUtils;
import com.hzjy.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ApiDictServiceImpl {
    @Autowired
    private ApiDictDataMapper apiDictDataMapper;
    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    public List<SysDictData> selectDictDataByType(String dictType)
    {
        List<SysDictData> dictDatas = DictUtils.getDictCache(dictType);
        if (StringUtils.isNotNull(dictDatas))
        {
            return dictDatas;
        }
        dictDatas = apiDictDataMapper.selectDictDataByType(dictType);
        if (StringUtils.isNotNull(dictDatas))
        {
            DictUtils.setDictCache(dictType, dictDatas);
            return dictDatas;
        }
        return null;
    }

    /**
     * 获取主页项目挂牌下的分类
     * @return
     */
    public Map typeList(){
        Map map=new HashMap();
        List<SysDictData>  projectTypeList=selectDictDataByType("project_type");
        List<SysDictData>  worksTypeList=selectDictDataByType("works_type");
        map.put("project_type","项目挂牌");
        map.put("works_type","项目挂牌");
        map.put("projectTypeList",projectTypeList);
        map.put("worksTypeList",worksTypeList);
        return map;
    }
}
